﻿namespace SRTSolutions.Elevate
{
    using System;

    /// <summary>
    /// Contains extension methods on the Tuple class.
    /// </summary>
    public static class TupleExtensions
    {
        /// <summary>
        /// Selects a value from this tuple using a function. Allows you to 
        /// assign descriptive names to the tuple elements to increase
        /// readability.
        /// </summary>
        /// <typeparam name="TResult">The type of the tuple's first component.</typeparam>
        /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
        /// <typeparam name="T1">The type of the first element.</typeparam>
        /// <param name="tuple">The tuple to select from.</param>
        /// <param name="selector">The selector.</param>
        /// <returns></returns>
        public static TResult Select<T1, T2, TResult>(this
#if NET_3_5
            Tuple<T1,T2>
#else
            System.Tuple<T1,T2> 
#endif 
            tuple, Func<T1, T2, TResult> selector)
        {
            if (selector == null)
                throw new ArgumentNullException("selector", "selector is null.");

            return selector(tuple.Item1, tuple.Item2);
        }
    }
}
